# -*- coding: utf-8 -*-
'''
@author: Johnny
@Created on: 2011-4-28
@version: 2011.4.28
@summary: Definition of Util class
'''
import os
import base64


class Util(object):
    '''
    Other used function for testing.
    '''
    
    
    @staticmethod
    def get_parent_path(strPath):
        '''
        Get parent path.
        Keyword arguments:
        strPath -- current path
        '''  
        if not strPath:  
            return None;  
    
        lsPath = os.path.split(strPath); 
        if lsPath[1]:  
            return lsPath[0];  
    
        lsPath = os.path.split(lsPath[0]);  
        return lsPath[0];     
    
    @staticmethod
    def get_current_path():
        path = os.path.abspath(os.path.dirname(__file__))
        return path
    
    @staticmethod
    def get_root_path():
        path = Util.get_current_path()
        root = Util.get_parent_path(Util.get_parent_path(path))
        root = root.replace("\\", "/")
        print root
        return root
    
    @staticmethod
    def pic_decoder(picstring, save_name):
        try:
            f = open(save_name, 'wb')
            f.write(picstring.decode('base64'))
            f.close()
            return "Success"
        except:
            return "Failed"
                  

if __name__== "__main__":
    print Util.get_current_path()
    